package org.vectrics.recruiter.struts.admin.job;

import javax.servlet.jsp.JspException;

import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.JobTerm;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;

/**
 * @author pgoette
 * Clase encargada de guardar el Term de un Job
 */
public class SaveJobTermAction extends VectricsStrutsAction {


	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {
		
		String forward = "success";
		JobTermForm form = (JobTermForm) actionData.getForm();
		JobTerm term = null;		
		
		if (actionData.wasButtonPressed("cancel")) {
			return forward;
		}
		
		if ((form.getId() == null)||(form.getId().trim().equals(""))) {
			term = new JobTerm();
		} else {
			term = RecruitServiceLocator.getJobProvider().findJobTerm(new Long(form.getId()));
		}
		
		term.setCode(form.getCode());
		term.setDescription(form.getDescription());
		
		RecruitServiceLocator.getJobProvider().saveJobTerm(term);
		
		return forward;
	}

}
